package com.conero.yangsu;

import com.conero.yangsu.controller.system.SystemLoginValidate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class YangsuConfigure implements WebMvcConfigurer {
    @Autowired
    SystemLoginValidate systemLoginValidate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // LINK https://www.jianshu.com/p/651af2107c0d
        //注册自定义拦截器
        InterceptorRegistration interceptor = registry.addInterceptor(systemLoginValidate);
        //拦截url
        interceptor.addPathPatterns("/system/**");
        //去除error和login
        //interceptor.excludePathPatterns("/error");
        interceptor.excludePathPatterns("/system/login");
        interceptor.excludePathPatterns("/system/login/**");
        interceptor.excludePathPatterns("/system/login/overdue");
        interceptor.excludePathPatterns("/system/userInfo");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //WebMvcConfigurer.super.addResourceHandlers(registry);
        registry.addResourceHandler("/**").addResourceLocations("/","classpath:/static");
    }
}
